package com.dys.entity;

import java.time.LocalDateTime;

/**
 * @Author: 疾风
 * @ClassName: CheckCode
 * @Description: 验证码对应的实体
 * @CreateDate: 2024/12/18
 * @Version: v1.0.0
 */
public class CheckCode {
    /**
     * 验证字符
     */
    private String code;
    /**
     * 过期时间
     */
    private LocalDateTime expireTime;

    public CheckCode() {
    }

    public CheckCode(String code, int expireTime) {
        this.code = code;
        // 返回指定的过期时间
        this.expireTime = LocalDateTime.now().plusSeconds(expireTime);
    }

    public CheckCode(String code){
        // 默认验证码60s后过期
        this(code,60);
    }

    /**
     * 判断验证码是否过期
     * @return true: 过期,false: 未过期
     */
    public boolean isExpired(){
        return this.expireTime.isBefore(LocalDateTime.now());
    }

    public String getCode() {
        return code;
    }
}
